home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 October: Technology Seed / ADC Seed CD - October 1999.toast / Carbon SDK 1.0d10c3 / Sample Code / AppearanceSample / LiveFeedbackDialog.cp < prev    next >
Encoding:
Text File  |  1999-05-01  |  3.6 KB  |  135 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        LiveFeedbackDialog.cp
  3.  
  4.     Contains:    Demonstration of live feedback.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (edv)    Ed Voas
  21.  
  22.     Change History (most recent first):
  23.  
  24.          <1>     9/11/97    edv        First checked in.
  25. */
  26.  
  27. //
  28. //    This file implements a dialog demonstrating live feedback with sliders
  29. //    and scroll bars. In this case, we have one of each control. They are
  30. //    connected to a text field showing the current value as well as each
  31. //    other, i.e. moving one automatically adjusts the other.
  32. //
  33.  
  34. #include "AppearanceSamplePrefix.h"
  35.  
  36. #include <TextUtils.h>
  37. #include "LiveFeedbackDialog.h"
  38. #include <Appearance.h>
  39. #include "AppearanceHelpers.h"
  40.  
  41. enum {
  42.     kScrollBar            = 1,
  43.     kSlider                = 2,
  44.     kStaticText            = 4
  45. };
  46.  
  47. ControlActionUPP    LiveFeedbackDialog::fProc = NewControlActionProc( LiveFeedbackDialog::LiveActionProc );
  48.  
  49. LiveFeedbackDialog::LiveFeedbackDialog() : BaseDialog( 1004 )
  50. {
  51.     if ( fWindow )
  52.     {
  53.             // These controls have been created with a live scrolling
  54.             // variant. We'll set the action proc using SetControlAction.
  55.             
  56.         GetDialogItemAsControl( fDialog, kScrollBar, &fScrollBar );
  57.         SetControlReference( fScrollBar, (long)this );
  58.         GetDialogItemAsControl( fDialog, kSlider, &fSlider );
  59.         SetControlReference( fSlider, (long)this );
  60.  
  61.         SetControlAction( fScrollBar, fProc );
  62.         SetControlAction( fSlider, fProc );
  63.     }
  64. }
  65.  
  66. LiveFeedbackDialog::~LiveFeedbackDialog()
  67. {
  68. }
  69.  
  70. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  71. //    Ä LiveActionProc
  72. //ããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããããã
  73. //    Here's our ControlActionUPP that also handles the indicator. At last, we can
  74. //    actually use the same function callback for both! There is a difference when
  75. //    called with the indicator as the part, as opposed to the up/down arrows, etc.
  76. //    If we are called because the indicator is being dragged, the value has already
  77. //    been calculated for us. If we are being called because the scroll bar arrows
  78. //    have been pressed, then we must determine how much to scroll by and set the
  79. //    scroll bar value accordingly. This allows us to have control over the amount
  80. //    that arrows scroll by. We can allow the indicator dragging to determine the
  81. //    value because the indicator always shows a percentage.
  82. //
  83. pascal void
  84. LiveFeedbackDialog::LiveActionProc( ControlHandle control, SInt16 part )
  85. {
  86.     ControlHandle        text;
  87.     Str255                valueText;
  88.     LiveFeedbackDialog*    dialog;
  89.     SInt16                startValue;
  90.     SInt16                delta;
  91.     
  92.     startValue = GetControlValue( control );
  93.     
  94.     delta = 0;
  95.     
  96.     switch ( part )
  97.     {
  98.         case kControlUpButtonPart:
  99.             if ( startValue > GetControlMinimum( control ) )
  100.                 delta = -1;
  101.             break;
  102.         
  103.         case kControlDownButtonPart:
  104.             if ( startValue < GetControlMaximum( control ) )
  105.                 delta = 1;
  106.             break;
  107.         
  108.         case kControlPageUpPart:
  109.             if ( startValue > GetControlMinimum( control ) )
  110.                 delta = -10;
  111.             break;
  112.         
  113.         case kControlPageDownPart:
  114.             if ( startValue < GetControlMaximum( control ) )
  115.                 delta = 10;
  116.             break;
  117.     }
  118.     if ( delta )
  119.         SetControlValue( control, startValue + delta );
  120.  
  121.     if ( part != kControlIndicatorPart && delta == 0 )
  122.         return;
  123.  
  124.     dialog = (LiveFeedbackDialog*)GetControlReference( control );
  125.  
  126.     GetDialogItemAsControl( dialog->fDialog, kStaticText, &text );
  127.     NumToString( GetControlValue( control ), valueText );
  128.     SetStaticTextText( text, valueText, true );
  129.  
  130.     if ( control == dialog->fScrollBar )
  131.         SetControlValue( dialog->fSlider, GetControlValue( control ) );
  132.     else
  133.         SetControlValue( dialog->fScrollBar, GetControlValue( control ) );
  134. }
  135.